package com.gupt.youhd.controller;
/*
@author name
@data 2023/6/20-16:19
*/



import com.gupt.youhd.common.R;
import com.gupt.youhd.entity.Address;
import com.gupt.youhd.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    //查询当前用户所有地址信息
    @GetMapping
    public R<List<Address>> address(HttpServletRequest request){
        List<Address> address = addressService.getAddress(request);
        return R.success(address);
    }

    /**
     * 修改用户当前地址信息：
     * 1回显当前地址信息
     * 2修改信息
     * @param request
     * @param address
     * @return
     */
    @PutMapping
    public R<String> update(HttpServletRequest request,@RequestBody Address address){
        addressService.updateAddress(request,address);
        return R.success("修改成功");
    }

    /**
     * 添加新的用户地址
     * @param request
     * @param address
     * @return
     */
    @PostMapping
    public R<String> insertAddress(HttpServletRequest request,@RequestBody Address address){
        addressService.insertAddress(request,address);
        return R.success("添加成功");
    }

    /**
     * 删除用户地址
     */
    @DeleteMapping
    public R<String> delAddress(int addressId){
        addressService.delAddress(addressId);
        return R.success("删除成功");
    }
}
